<?php
/**
 * Created by PhpStorm.
 * User: chenzhitao
 * Date: 2018/3/20
 * Time: 上午9:38
 */

namespace app\index\controller;

use app\index\model\Dist;
use app\index\model\News;
use app\index\model\SubCategory;
use app\index\service\CompanyService;
use app\index\service\NewsService;
use think\Controller;
use app\index\model\Company as companyModel;

class Company extends BaseController
{
    /**
     * 显示资源列表
     *
     * @return \think\Response
     */
    public function index($options, $page)
    {
//
        if($options){
            $option_array = explode("g",$options);
            $staId=$option_array[0];
            $id = $option_array[1];
            $idCity = $option_array[2];
        }else{
            $staId = 'multi';
            $id = 0;
            $idCity = 0;
        }

        if($page == null){
            $page = 1;
        }

        if($staId == null){
            $staId = 'multi';
        }
        if($id == null){
            $id = 0;
        }
        if($idCity == null){
            $idCity = 0;
        }
        if($page != 1){
            $pagetext = '第'.$page.'页';
        }else{
            $pagetext = '';
        }

        
        $category_name = SubCategory::getCategoryNameById($id);
        $city_name = Dist::getDistNameById($idCity);
        $company_list = CompanyService::getCompanyList($page);
        $this->assign("company_list",$company_list);

        return $this->fetch("companyList",["staId"=>$staId, "id"=>$id, "idCity"=>$idCity ,"category_name"=>$category_name,"city_name"=>$city_name,"page"=>$page,"pagetext"=>$pagetext]);
    }
    public function getDeitail($id){
        $seoInfo = companyModel::getSeoInfoById($id);
        $title = $seoInfo['title'];
        $desc = $seoInfo['desc'];
        $company_detail = CompanyService::getCompanyDetail($id);
        $this->assign("company_detail",$company_detail);
        $hot_news = NewsService::getHotNewsList(4);
        $this->assign("hot_news",$hot_news);
        return $this->fetch("companyDetail",["id"=>$id,"title"=>$title,"desc"=>$desc]);
    }
    public function test(){
        return "das";

    }
   
}